<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app1"></div>
    <div id="app2"></div>
    <div id="app3"></div>

    <script type="text/javascript" src="../js/react.development.js"></script>
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <!-- 引入prop-type 用于限制props属性标签 -->
    <script type="text/javascript" src="../js/prop-types.js"></script>
    
    <script type="text/babel">
        // 假数据
        const obj = {name:"张三",age:18,sex:"男"}
        // 创建组件
        class Person extends React.Component {
            render() {
                const {name,age,sex} = this.props
                return (
                    <div>
                        <span>{name}</span>
                        <span>{age}</span>
                        <span>{sex}</span>
                    </div>
                )
            }
            // 对标签属性进行限制
            static propTypes = {
                name:PropTypes.string.isRequired,//限制name必传且为String类型
                age:PropTypes.number,//限制age为number类型
                sex:PropTypes.string,//限制sex为String类型
                speak:PropTypes.func//限制speak为函数类型
            }
            static defaultProps = {
                age:18,//指定age默认值
                sex:'保密'//指定sex默认值
            }
        }
        

        function speak() {
            console.log('hello');
        }
        // 渲染组件
        ReactDOM.render(<Person name="李四" age={20} sex="男" speak={speak}/>,document.querySelector('#app1'))
        ReactDOM.render(<Person name="李五"/>,document.querySelector('#app3'))
        // 批量传递props/批量传递标签属性
        ReactDOM.render(<Person {...obj}/>,document.querySelector('#app2'))
    </script>
</body>
</html>